Skip to content

feat(protographic): multiple keys and compound keys for entity rpc#2105

Merged
endigma merged 6 commits intomainfrom
jesse/eng-7737-protographic-allow-use-of-multiple-and-compound-keys
Aug 6, 2025
Merged

feat(protographic): multiple keys and compound keys for entity rpc#2105
endigma merged 6 commits intomainfrom
jesse/eng-7737-protographic-allow-use-of-multiple-and-compound-keys

Conversation

@endigma
Copy link
Copy Markdown
Member

@endigma endigma commented Aug 4, 2025

Summary by CodeRabbit

  • New Features

    • Added support for multiple and compound @key directives on entity types, enabling generation of multiple distinct lookup RPCs and messages for each key combination.
  • Bug Fixes

    • Corrected handling of entity key mappings to ensure all @key directives are processed and reflected in generated mappings and proto files.
  • Tests

    • Introduced new test cases to verify correct mapping and proto generation for entities with multiple and compound @key directives. Updated existing tests to cover these scenarios.

Checklist

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 4, 2025

Walkthrough

This change set refactors the handling of GraphQL entity @key directives in both the mapping and proto generation logic to support multiple and compound keys per entity. It removes single-key-specific naming helpers, updates visitors to process all @key directives, and expands the test suites with cases for multiple and compound keys.

Changes

Cohort / File(s) Change Summary
Naming Convention Refactor
protographic/src/naming-conventions.ts
Removed single-key request/response naming functions; updated method name generator to handle multiple key fields separated by spaces or commas, converting them to camel case and joining with "And".
Mapping Visitor Multi-Key Support
protographic/src/sdl-to-mapping-visitor.ts
Refactored to extract all @key directives per type, treating each as a distinct raw key string; replaced single-key helper methods with multi-key versions; unified naming logic for RPCs and messages; removed unused imports.
Proto Visitor Multi-Key & Compound Key Support
protographic/src/sdl-to-proto-visitor.ts
Refactored to extract all @key directives and generate separate RPCs and messages for each; updated request message creation to handle multiple key fields split from raw key strings; adjusted field number reconciliation and lock manager calls; removed unused imports; added new helper methods.
Mapping Tests: Multi/Compound Key Cases
protographic/tests/sdl-to-mapping/03-federation.test.ts
Added tests verifying multiple and compound @key directives produce multiple distinct entity mappings; included tests for malformed keys and mixed single/compound keys; updated snapshots accordingly.
Proto Tests: Multi/Compound Key Cases
protographic/tests/sdl-to-proto/04-federation.test.ts
Added tests verifying proto generation for entities with multiple and compound @key directives; confirmed generation of multiple lookup RPCs and messages per key variant; updated snapshots to reflect renamed lookup RPCs/messages for compound keys.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

  • Complexity: High, due to core logic refactoring across multiple modules, new helper methods, changes to exported method signatures, and expanded test coverage for nuanced multi-key scenarios. Review requires careful validation of both logic and test outputs.

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2bd165c and 2086794.

📒 Files selected for processing (4)
  • protographic/src/naming-conventions.ts (1 hunks)
  • protographic/src/sdl-to-proto-visitor.ts (5 hunks)
  • protographic/tests/sdl-to-mapping/03-federation.test.ts (2 hunks)
  • protographic/tests/sdl-to-proto/04-federation.test.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • protographic/src/naming-conventions.ts
  • protographic/tests/sdl-to-proto/04-federation.test.ts
  • protographic/tests/sdl-to-mapping/03-federation.test.ts
  • protographic/src/sdl-to-proto-visitor.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Analyze (go)
  • GitHub Check: Analyze (javascript-typescript)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jesse/eng-7737-protographic-allow-use-of-multiple-and-compound-keys

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@endigma endigma force-pushed the jesse/eng-7737-protographic-allow-use-of-multiple-and-compound-keys branch from b123eed to 860304c Compare August 4, 2025 15:42
@endigma endigma changed the title feat: multiple keys and compound keys for entity rpc feat(protographic): multiple keys and compound keys for entity rpc Aug 4, 2025
Copy link
Copy Markdown
Contributor

@Noroth Noroth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good so far

Comment thread protographic/src/naming-conventions.ts Outdated
@endigma endigma marked this pull request as ready for review August 5, 2025 08:54
@endigma endigma requested a review from StarpTech as a code owner August 5, 2025 08:54
@endigma endigma force-pushed the jesse/eng-7737-protographic-allow-use-of-multiple-and-compound-keys branch from 5307c98 to 1eeaaae Compare August 5, 2025 08:54
@endigma endigma requested a review from Noroth August 5, 2025 08:55
Noroth
Noroth previously approved these changes Aug 5, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
protographic/src/naming-conventions.ts (1)

53-57: LGTM! The compound key handling logic is well-implemented.

The updated function correctly handles both single and compound keys by splitting the keyString and joining with "And". This addresses the requirement for multiple and compound keys while maintaining backward compatibility with single keys.

However, consider adding validation for edge cases:

 export function createEntityLookupMethodName(typeName: string, keyString: string = 'id'): string {
+  if (!keyString.trim()) {
+    throw new Error('keyString cannot be empty');
+  }
   const fields = keyString.trim().split(' ');
   const keyPart = fields.map((field) => upperFirst(camelCase(field))).join('And');
   return `Lookup${typeName}By${keyPart}`;
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1eeaaae and e585738.

📒 Files selected for processing (2)
  • protographic/src/naming-conventions.ts (1 hunks)
  • protographic/tests/sdl-to-mapping/03-federation.test.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • protographic/tests/sdl-to-mapping/03-federation.test.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e585738 and 3c30dea.

📒 Files selected for processing (1)
  • protographic/src/naming-conventions.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)

Comment thread protographic/src/naming-conventions.ts Outdated
@endigma endigma force-pushed the jesse/eng-7737-protographic-allow-use-of-multiple-and-compound-keys branch from 44e1d59 to 2bd165c Compare August 6, 2025 09:10
@Noroth Noroth self-requested a review August 6, 2025 09:28
@Noroth Noroth dismissed their stale review August 6, 2025 09:29

reviewing changes

Copy link
Copy Markdown
Contributor

@Noroth Noroth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@endigma endigma merged commit a69e5e5 into main Aug 6, 2025
8 checks passed
@endigma endigma deleted the jesse/eng-7737-protographic-allow-use-of-multiple-and-compound-keys branch August 6, 2025 10:12
@Noroth Noroth mentioned this pull request Sep 30, 2025
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants